package org.platform.lwc.redis.config;


import org.platform.lwc.redis.aop.LockAspect;
import org.platform.lwc.redis.factory.redission.RedissonClientFactory;
import org.platform.lwc.redis.utils.RedisFuncLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;


@Configuration
public class RedissonConfiguration {


    @Autowired
    private RedisProperties redisProperties;

    /**
     * @Description: property完整名称或部分名称（可与prefix组合使用，组成完整的property名称），与value不可同时使用
     *               havingValue 与name组合使用，比较获取到的属性值与havingValue给定的值是否相同，相同才加载配置
     *               matchIfMissing 缺少该property时是否可以加载。如果为true，没有该property也会正常加载；反之报错
     * @Author: lwc
     * @Date: 2022-03-30 17:05
     */

    @Bean(destroyMethod = "shutdown")
    @ConditionalOnMissingBean(RedissonClient.class)
    public RedissonClient redissonClient() throws IOException {
     return new RedissonClientFactory().getRedissonClient(redisProperties);
    }

    @Bean
    public LockAspect lockAspect()  {
     return new LockAspect();
    }

    @Bean
    public RedisFuncLock redisFuncLock()  {
        return new RedisFuncLock();
    }


}